<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2016/12/21
 * Time: 11:00
 */

//Serializable {
//	/* 方法 */
//	abstract public string serialize ( void )
//	abstract public mixed unserialize ( string $serialized )
//}

class TestSerializable implements Serializable {

	private $obj;

	function __construct( $obj ) {
		$this->obj = $obj;
	}

	/**
	 * String representation of object
	 * @link http://php.net/manual/en/serializable.serialize.php
	 * @return string the string representation of the object or null
	 * @since 5.1.0
	 */
	public function serialize() {
		$this->obj = serialize( $this->obj );
	}

	/**
	 * Constructs the object
	 * @link http://php.net/manual/en/serializable.unserialize.php
	 *
	 * @param string $serialized <p>
	 * The string representation of the object.
	 * </p>
	 *
	 * @return void
	 * @since 5.1.0
	 */
	public function unserialize( $serialized ) {
		$this->obj = unserialize( $serialized );
	}

	public function get(){
		return $this->obj;
	}
}

$testSerializable = new TestSerializable( "string" );
$testSerializable->serialize();
echo $testSerializable->get().PHP_EOL;
$testSerializable->unserialize($testSerializable->get());
echo $testSerializable->get();